use spring_axum::{Advice, AxumRequest, AxumResponse, AxumBody};

#[derive(Default)]
pub struct LoggingAdvice;

impl Advice for LoggingAdvice {
    fn pointcut_expr(&self) -> &'static str {
        // 命中 GET 和 POST 的 /hello 路由（演示效果明显）
        "GET,POST /hello"
    }

    fn before(&self, req: AxumRequest<AxumBody>) -> AxumRequest<AxumBody> {
        tracing::info!(target = "advice", "--> {} {}", req.method(), req.uri());
        req
    }

    fn after(&self, res: AxumResponse<AxumBody>) -> AxumResponse<AxumBody> {
        tracing::info!(target = "advice", "<-- {}", res.status());
        res
    }
}

// 注册到 inventory，auto_discover! 会自动挂载
spring_axum::advice!(LoggingAdvice);